% Read the data into arrays, then fill empty slots
%[T E1 E2 O1 R SM TM EV] = textscan('../data/eeg.dat', '%f,%f,%f,%f,%f,%f,%f,%f');
% [T E1 E2 O1] = textread('eeg.dat', '%f,%f,%f,%f');
% [T2 S]       = textread('hyp.dat', '%f,%f');

DataFile= csvread('st7132j0-rec_data.txt',1,0);
ResultFile= csvread('st7132j0-hyp_data.txt',1,0);

%DataFile
Time = DataFile(:,1);
EEG1 = DataFile(:,2);

EEG2 = DataFile(:,3);
EOG = DataFile(:,4);

Time2 =  ResultFile(:,1);
Stage =  ResultFile(:,2);
% Each epoch is 3000 deciseconds
L = length(Time);
l = 30*100;

% For each epoch, split the data into 30-second intervals,
% then compute attribute values
for i=1:1:L/l
  X = (i-1)*l+1:1:min(i*l,L);
  EEG1_e = EEG1(X);
  EEG2_e = EEG2(X);
  EOG_e = EOG(X);

  Data(i,1) = mean(abs(EEG1_e));
  Data(i,2) = mean(abs(EEG2_e));
  Data(i,3) = mean((EOG_e));

  Data(i,4) = max(abs(EEG1_e));
  Data(i,5) = max(abs(EEG2_e));
  Data(i,6) = max(abs(EOG_e));

  Data(i,7) = Frequency(EEG1_e);
  Data(i,8) = Frequency(EEG2_e);

  Class(i) = Stage(i);
end

% Create the Naive Bayes classifier object
nb = NaiveBayes.fit(Data,Class);
display(nb);
